package com.atguigu.gilimall.thirdpart.service.impl;

import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
import com.aliyun.dysmsapi20170525.models.SendSmsResponseBody;
import com.atguigu.gilimall.thirdpart.service.SmsService;
import com.atguigu.gilimall.thirdpart.utils.SmsUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author ShiJieLin
 * @Date 2022/4/20 21:47
 * @Version 1.0
 */
@Service
@Slf4j
public class SmsServiceImpl implements SmsService {

    @Override
    public Boolean send(String phone, Map<String, Object> param) {

        if (StringUtils.isEmpty(phone)){
            return false;
        }
        try {
            SendSmsResponse sms = SmsUtil.createSms(phone, param);
            SendSmsResponseBody body = sms.getBody();

            String result = body.getCode();
            log.info("result: ----> " + result);
            if(StringUtils.equals(result, "OK")){
                return true;
            }else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }

    }
}
